﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HCFramework.API.LINQ;

namespace C
{
    public class OrderHistoryController
    {
        public static void Insert(OrderHistory a)
        {
            HCDataContext db = new HCDataContext();
            a.Date = DateTime.Now;
            db.OrderHistories.InsertOnSubmit(a);
            db.SubmitChanges();
        }

        public static void Insert(int orderId, E.OrderStatus status)
        {
            OrderHistory oh = new OrderHistory();
            oh.OrderID = orderId;
            oh.OrderStatus = (int)status;
            Insert(oh);
        }

        public static void Update(OrderHistory a, HCDataContext db)
        {
            //db.SubmitChanges();
            throw new Exception("OrderHistory can not be updated");
        }

        public static void Delete(int id)
        {
            //HCDataContext db = new HCDataContext();
            //OrderHistory a = db.OrderHistories.Where(
            //    ik => ik.OrderHistoryID == id).First();
            //db.OrderHistories.DeleteOnSubmit(a);
            //db.SubmitChanges();
            throw new Exception("OrderHistory can not be deleted");
        }

        public static OrderHistory GetByID(int id, HCDataContext db)
        {
            return db.OrderHistories.Where(
                ik => ik.OrderHistoryID == id).FirstOrDefault();
        }

        public static OrderHistory GetByID(int id)
        {
            return GetByID(id, new HCDataContext());
        }
    }
}